package dao;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.transaction.annotation.Transactional;

import bean.User;


@Transactional
public class DepositDAO {
    protected static final Logger log = LoggerFactory.getLogger(DepositDAO.class);
    // property constants
    public static final String ID = "id";
    public static final String CODE = "code";
    
    protected SessionFactory sessionFactory;

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    protected Session getCurrentSession() {
        return sessionFactory.getCurrentSession();
    }

    protected void initDao() {
        // do nothing
    }
    
    public void save(User transientInstance) {
        log.debug("saving Deposit instance");
        try {
            getCurrentSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }

    public void delete(User persistentInstance) {
        log.debug("deleting Deposit instance");
        try {
            getCurrentSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }

    public User findById(java.lang.Integer id) {
        log.debug("getting Deposit instance with id: " + id);
        try {
            User instance = (User) getCurrentSession().get("bean.Deposit", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    public static DepositDAO getFromApplicationContext(ApplicationContext ctx) {
        return (DepositDAO) ctx.getBean("DepositDAO");
    }


}
